/*
 * @Author: wangchao
 * @Date: 2025-06-05 11:40:02
 * @LastEditors: wangchao
 * @LastEditTime: 2025-06-05 13:04:13
 * @FilePath: \UX6_ATE-RDO\applications\main.c
 * @Description:
 * Copyright (c) 2025 by Bingshan Guardian, All Rights Reserved.
 */

#include <rtthread.h>
#include "u_port.h"

#define DBG_TAG "MAIN"
#define DBG_LVL DBG_LOG
#include <rtdbg.h>

int main(void)
{
    LOG_I("Resistors Switching Board Driver.");

    u_port_init();

    extern int vbc_modbus_rtu_slave_thread(void);

    if (vbc_modbus_rtu_slave_thread() != RT_EOK)
    {
        LOG_E("Failed to start Modbus RTU slave thread.");
        return -1;
    }

    while (1)
    {
        for (int i = 0; i < 16; i++)
        {
            if ((PINS_WORD >> i) & 0x01)
            {
                rt_pin_write(DO_PINS[i], PIN_HIGH);
                LOG_I("DO%d set to HIGH", i + 1);
            }
            else
            {
                rt_pin_write(DO_PINS[i], PIN_LOW);
                LOG_I("DO%d set to LOW", i + 1);
            }
        }

        rt_thread_mdelay(50);
    }

    return RT_EOK;
}
